<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App;

class Collection extends Model
{

	public function getName()
	{
		if (App::getLocale() == 'cn' && $this->cn_name) {
			return $this->cn_name;
		}
		return $this->name;
	}

	public function getAbstract()
	{
		if (App::getLocale() == 'cn' && $this->cn_abstract) {
			return $this->cn_abstract;
		}

		return $this->abstract;
	}

	public function scopeOnline($query)
	{
		return $query->where('is_online', 1);
	}

	public function getArticleCount()
	{
		return CollectionArticle::where('c_id', $this->id)->count();
	}
	public function articles()
	{
		return $this->belongsToMany(Article::class, 'collection_articles', 'c_id', 'a_id');
	}

	public function isIncoming()
	{
		return false;
	}
}
